package com.example.zg.zg_312_ordering_new.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zg.zg_312_ordering_new.R;
import com.example.zg.zg_312_ordering_new.beans.Comment;

import java.util.List;

public class CommentAdapter extends RecyclerView.Adapter<CommentItemViewHolder> {
    private Context context;
    private List <Comment> List;

    public void setData(List<Comment> list){
        this.List=list;
        notifyDataSetChanged();//通知数据集发生变化
    }

    @NonNull
    @Override
    public CommentItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View itemView = layoutInflater.inflate(R.layout.comment_layout,parent,false);
        CommentItemViewHolder viewHolder = new CommentItemViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull CommentItemViewHolder holder, int position) {
        final Comment comment = List.get(position);
        holder.name.setText(comment.getContent());
        holder.time.setText(comment.getComment_time());
    }

    @Override
    public int getItemCount() {
        if(List!=null)
            return List.size();
        else
            return 0;
    }
}
